package com.clannad.educms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.clannad.commonutils.R;
import com.clannad.educms.entity.CrmBanner;
import com.clannad.educms.service.CrmBannerService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/educms/banner")
//@CrossOrigin
public class BannerAdminController {
    @Autowired
    CrmBannerService crmBannerService;
    @GetMapping("pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable Long page,@PathVariable Long limit){
        Page<CrmBanner> page1=new Page(page,limit);
        crmBannerService.page(page1,null);
        return R.ok().data("items",page1.getRecords()).data("total",page1.getTotal());
    }

    @PostMapping("addOrUpdataBanner")
    public R addOrUpdataBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.saveOrUpdate(crmBanner);
        return R.ok();
    }

    @DeleteMapping("remove/{id}")
    public R removeById(@PathVariable Long id){
        crmBannerService.removeById(id);
        return R.ok();
    }

    @GetMapping("getbanner/{id}")
    public R get(@PathVariable Long id){
        CrmBanner byId = crmBannerService.getById(id);
        return R.ok().data("banner",byId);
    }
}

